import crcmod
from simulators.SuperFlow import SuperFlow
from simulators.HashFlow import HashFlow
from simulators.HashPipe import HashPipe
from simulators.Elastic import HardwareElastic
from simulators.PRECISION import PRECISION
from simulators.FlowRadar import FlowRadar
# from simulators.FlowClassifier import FlowClassifier
from 文件工具 import 恢复数据
from os import path


def 获取流记录集(算法, 协议, 内存, 带宽, 符列, 戳列):
    assert("sf" == 算法 or 带宽 > 0)
    print("算法:%s, 协议:%s, 内存:%.3f, 带宽:%.3f" % (算法, 协议, 内存, 带宽/1000000.0))
    备份文件 = "./flows.%s.proto.%s.mem.%.2f.bandwidth.%.2f.json" % (算法, 协议, 内存, 带宽/1000000.0)
    if not path.exists(备份文件):
        if "sf" == 算法:
            al = SuperFlow(内存, 协议=协议)
        elif "pr" == 算法:
            al = PRECISION(内存, 协议=协议)
        elif "hf" == 算法:
            al = HashFlow(内存, 协议=协议)
        elif "hp" == 算法:
            al = HashPipe(内存, 协议=协议)
        elif "fr" == 算法:
            al = FlowRadar(内存, 协议=协议)
        elif "el" == 算法:
            al = HardwareElastic(内存, 协议=协议)
        else:
            raise SystemExit("不能识别算法: %s" % 算法)
        al.计算导出周期(带宽)
        al.重放数据包序列(符列, 戳列)
        al.备份(备份文件)
    res = 恢复数据(备份文件)["流记录集"]
    return res
